package com.thams.util;

import java.lang.reflect.Field;

import org.apache.commons.lang.StringUtils;

import com.thams.entity.BasPart;
import com.thams.entity.Inventory;
import com.thams.entity.InventoryClass;
import com.thams.entity.InventorySub;
import com.thams.entity.SoSodetails;
import com.thams.entity.SoSomain;

public class GenerateInsertUtil {
	public static String generateInsert(String tablename,Class c){
		String fields="",jfields="";
		Field[] fieldsArray = c.getDeclaredFields();
		for (Field field : fieldsArray) {
			if(field.getName().equals("children")||field.getName().equals("serialVersionUID")||field.getName().equals("pubufts")||field.getName().equals("ufts")||field.getName().equals("dufts")){
				continue;
			}
			fields += field.getName()+",";
			jfields += "#"+field.getName()+"#,";
		}
		String sb = "INSERT INTO "+tablename+"("+StringUtils.removeEnd(fields, ",")+") VALUES ("+StringUtils.removeEnd(jfields, ",")+")";
		return sb;
	}
	public static void main(String[] args) {
		System.out.println(generateInsert("InventoryClass",InventoryClass.class));
		System.out.println(generateInsert("Inventory_Sub",InventorySub.class));
		System.out.println(generateInsert("Inventory",Inventory.class));
		System.out.println(generateInsert("SO_SOMain",SoSomain.class));
		System.out.println(generateInsert("SO_SODetails",SoSodetails.class));
		System.out.println(generateInsert("bas_part",BasPart.class));
	}
}
